package cn.terminus.biz.customer.custombusinessinfo;

import cn.terminus.biz.customer.common.AbstractTerminusManager;
import cn.terminus.common.customer.bean.custombusinessinfo.dto.*;
import cn.terminus.data.customer.custombusinessinfo.dao.CustomBusinessInfoDao;
import cn.terminus.result.common.exception.DataAccessException;
import cn.terminus.result.common.page.TerminusPageAble;
import cn.terminus.result.common.page.TerminusPageInfo;
import cn.terminus.result.common.util.BeanCopyUtils;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * (CustomBusinessInfo)表服务实现类
 *
 * @author makejava
 * @since 2021-07-08 11:18:36
 */
@Component
public class CustomBusinessInfoManager extends AbstractTerminusManager {
    @Autowired
    private CustomBusinessInfoDao customBusinessInfoDao;

    public Integer add(CustomBusinessInfoNewDto dto) throws DataAccessException {
        try {
            return customBusinessInfoDao.add(dto);
        } catch (Exception e) {
            logger.error("CustomBusinessInfoManager新增失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public Integer update(CustomBusinessInfoNewDto dto) throws DataAccessException {
        try {
            return customBusinessInfoDao.update(dto);
        } catch (Exception e) {
            logger.error("CustomBusinessInfoManager更新失败，原因：", e);
            throw new DataAccessException(e);
        }
    }


    public List<CustomBusinessInfoResultDto> query(CustomBusinessInfoQueryDto dto) throws DataAccessException {
        try {
            return customBusinessInfoDao.query(dto);
        } catch (Exception e) {
            logger.error("CustomBusinessInfoManager查询失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public Integer delete(CustomBusinessInfoDeleteDto dto) throws DataAccessException {
        try {
            return customBusinessInfoDao.delete(dto);
        } catch (Exception e) {
            logger.error("CustomBusinessInfoManager删除失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public TerminusPageAble<CustomBusinessInfoResultDto> page(CustomBusinessInfoQueryDto dto, TerminusPageInfo page) throws DataAccessException {
        try {
            PageHelper.startPage(page.getCurrentPage(), page.getPageSize());
            Page<CustomBusinessInfoResultDto> result = (Page<CustomBusinessInfoResultDto>) customBusinessInfoDao.query(dto);
            return new TerminusPageAble<>(BeanCopyUtils.copy(result.getResult(), CustomBusinessInfoResultDto.class), page, result.getTotal());
        } catch (Exception e) {
            logger.error("CustomBusinessInfoManager分页查询失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public Long getBussinessId(Long id) throws DataAccessException {
        try {
            return customBusinessInfoDao.getBussinessId(id);
        } catch (Exception e) {
            logger.error("CustomBusinessInfoManager删除失败，原因：", e);
            throw new DataAccessException(e);
        }
    }
}
